package org.fkjava.oa.identity.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.fkjava.common.dao.GeneratorDao;
import org.fkjava.common.util.CommonContants;
import org.fkjava.common.util.pager.PageModel;
import org.fkjava.oa.identity.dao.DeptDao;
import org.fkjava.oa.identity.dao.JobDao;
import org.fkjava.oa.identity.dao.ModuleDao;
import org.fkjava.oa.identity.dao.PopedomDao;
import org.fkjava.oa.identity.dao.RoleDao;
import org.fkjava.oa.identity.dao.UserDao;
import org.fkjava.oa.identity.domain.Dept;
import org.fkjava.oa.identity.domain.Module;
import org.fkjava.oa.identity.domain.Popedom;
import org.fkjava.oa.identity.domain.Role;
import org.fkjava.oa.identity.domain.User;
import org.fkjava.oa.identity.dto.UserModule;
import org.fkjava.oa.identity.service.IdentityService;
import org.fkjava.oa.util.OaContants;
import org.fkjava.oa.util.OaException;
import org.fkjava.oa.util.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/** 
 *  系统管理的业务层实现类   
 */
@Service("identityService") // 配置业务层的bean
//@Transactional(readOnly=false,rollbackFor=java.lang.RuntimeException.class)
@Transactional(readOnly=false)
public class IdentityServiceImpl implements IdentityService {
	// session
	/** 定义dao对象 */
	@Autowired  // bytype
	@Qualifier("deptDao") // byName
	private DeptDao deptDao;
	
	@Autowired  // bytype
	@Qualifier("jobDao") // byName
	private JobDao jobDao;
	
	@Autowired  // bytype
	@Qualifier("userDao") // byName
	private UserDao userDao;
	
	@Autowired  // bytype
	@Qualifier("moduleDao") // byName
	private ModuleDao moduleDao;
	
	@Autowired  // bytype
	@Qualifier("generatorDao") // byName
	private GeneratorDao generatorDao;
	
	@Autowired  // bytype
	@Qualifier("roleDao") // byName
	private RoleDao roleDao;
	
	@Autowired  // bytype
	@Qualifier("popedomDao") // byName
	private PopedomDao popedomDao;
	
	@Transactional(readOnly=true)
	@Override
	public List<Dept> getAllDepts(){
		// 思考异常的处理 
		try {
			List<Dept> depts = deptDao.find(Dept.class);
			// 取延迟加载的属性 ,会话此时并没有关闭
			for(Dept dept : depts){
				if(dept.getCreater()!=null)dept.getCreater().getName();
				if(dept.getModifier()!=null)dept.getModifier().getName();
			}
			
//			/**  添加一个职位  */
//			Job job = new Job();
//			job.setCode("0010");
//			job.setName("老板");
//			job.setRemark("老板..");
//			jobDao.save(job);
			
			return depts;
		} catch (Exception e) {
			throw new OaException("查询部门失败了", e); 
		}
	}

	@Override
	public String login(Map<String, Object> params) {
		JSONObject result = new JSONObject(); // 
		try {
			String userId = (String) params.get("userId");
			String passWord = (String) params.get("passWord");
			String vcode = (String) params.get("vcode");
			HttpSession session = (HttpSession) params.get("session");
			if(StringUtils.isEmpty(userId) || StringUtils.isEmpty(passWord)|| StringUtils.isEmpty(vcode) ){
				result.put("status", 0);
				result.put("tip", "参数有为空的");
			}else{
				/** 参数不为空  */
				/** 校验验证码是否正确 
				 *  获取session中当前用户对应的验证码 
				 * */
				String sysCode = (String) session.getAttribute(CommonContants.VERIFY_SESSION);
				if(vcode.equalsIgnoreCase(sysCode)){
					/** 验证码正确了  */
					/** 根据登录的用户名去查询用户: 判断登录名是否存在  */
					User user = getUserById(userId);
					if(user!=null){
						/** 登录名存在  */
						/** 判断密码 */
						if(user.getPassWord().equals(passWord)){
							 /** 判断用户是否已经被激活了 */
							if(user.getStatus() == 1){
								session.setAttribute(OaContants.USER_SESSION, user);
								result.put("status",1);
								result.put("tip", "登录成功");
								/** 把登录成功的用户存入到UserHolder*/
								UserHolder.addCurrentUser(user);
								/** 2.当用户一登录进入系统的时候,就应该立即去查询该用户所拥有
	      									的全部操作权限 --> 存入到当前用户的Session会话中  */
								Map<String,List<String>> userAllOperasPopedomUrls = getUserAllOperasPopedomUrls();
								session.setAttribute(OaContants.USER_ALL_OPERAS_POPEDOM_URLS, userAllOperasPopedomUrls);
										
 							}else{
								result.put("status",5);
								result.put("tip", "您的账号未被激活,请联系管理员激活!");
							}
						}else{
							/** 密码错误     */
							result.put("status", 2);
							result.put("tip", "密码错误了");
						}
					}else{
						/** 登录名不存在  */
						result.put("status", 3);
						result.put("tip", "没有该账户");
					}
				}else{
					/** 验证码不正确 */
					result.put("status", 4);
					result.put("tip", "验证码不正确");
				}
			}
			return result.toString();
		} catch (Exception e) {
			throw new OaException("异步登录业务层抛出异常了", e);
		}
		
	}

	private Map<String, List<String>> getUserAllOperasPopedomUrls() {
		try {
			/** 查询用户所拥有的所有操作权限编号 
			 *  [000100010001,000100010002]
			 * */
			List<String> userAllPopedomOperasCodes = popedomDao.getUserPopedomOperasCodes();
			
			if(userAllPopedomOperasCodes!=null && userAllPopedomOperasCodes.size()>0 ){
				 Map<String, List<String>> userAllOperasPopedomUrls = new HashMap<>();
				 String moduleUrl = "" ;
				 List<String> moduleOperaUrls = null;
				 for(String operaCode : userAllPopedomOperasCodes){
					 /** 先得到模块的编号   */
					 String parentModuleCode = operaCode.substring(0, operaCode.length() - OaContants.CODE_LEN);
					 /** 父模块地址 */
					 moduleUrl = getModuleByCode(parentModuleCode).getUrl();
					 /** 判断map集合中是否已经存在该父模块地址 */
					 if(!userAllOperasPopedomUrls.containsKey(moduleUrl)){
						 moduleOperaUrls = new ArrayList<String>();
						 userAllOperasPopedomUrls.put(moduleUrl, moduleOperaUrls);
					 }
					 moduleOperaUrls.add(getModuleByCode(operaCode).getUrl());
				 }
				 /**
				  * { /identity/user/selectUser.jspx=[/identity/user/selectUser.jspx, 
				  *                                    /identity/user/preUser.jspx], 
				  *   /admin/leave/mgrLeaveItem.jspx=[/admin/leave/mgrLeaveItem.jspx, 
				  *                                   /admin/leave/selectLeaveItem.jspx,
				  *                                    /admin/leave/checkLeaveItem.jspx], 
				  *   /admin/leave/mgrLeaveType.jspx=[/admin/leave/selectLeaveType.jspx,
				  *                                   /admin/leave/addLeaveType.jspx,
				  *                                    /admin/leave/updateLeaveType.jspx,
				  *                                    /admin/leave/deleteLeaveType.jspx,
				  *                                     /admin/leave/mgrLeaveType.jspx], 
				  *   /identity/module/mgrModule.jspx=[/identity/module/mgrModule.jspx, 
				  *                                   /identity/module/getModulesByParent.jspx,
				  *                                   /identity/module/addModule.jspx, 
				  *                                   /identity/module/deleteModule.jspx,
				  *                                    /identity/module/updateModule.jspx], 
				  *   /admin/leave/selectUserLeave.jspx=[/admin/leave/selectUserLeave.jspx, /admin/leave/addUserLeave.jspx, /admin/leave/updateUserLeave.jspx, /admin/leave/deleteUserLeave.jspx], /identity/role/selectRole.jspx=[/identity/role/selectRole.jspx, /identity/role/addRole.jspx, /identity/role/deleteRole.jspx, /identity/role/updateRole.jspx, /identity/role/selectRoleUser.jspx, /identity/role/bindUser.jspx, /identity/role/unBindUser.jspx, /identity/popedom/mgrPopedom.jspx, /identity/popedom/selectOpreasByParent.jspx, /identity/popedom/bindPopedom.jspx], /admin/leave/selectAuditLeave.jspx=[/admin/leave/selectAuditLeave.jspx, /admin/leave/auditLeaveSheet.jspx]}
				  * */
				 return userAllOperasPopedomUrls;
			}
			return null;
		} catch (Exception e) {
			throw new OaException("登录查询用户的操作权限出现异常", e);
		}
		
	}

	public User getUserById(String userId) {
		try {
			User user = userDao.get(User.class, userId);
			// 获取延迟加载的属性
			if(user.getDept()!=null)user.getDept().getName();
			if(user.getJob()!=null)user.getJob().getName();
			if(user.getCreater()!=null)user.getCreater().getName();
			if(user.getModifier()!=null)user.getModifier().getName();
			if(user.getChecker()!=null)user.getChecker().getName();
			return user;
		} catch (Exception e) {
			throw new OaException("查询用户失败了", e);
		}
	}
	
	@Override
	public void updateSelf(User user,HttpSession session) {
		try {
			/** 1.持久化修改   */
			User sessionUser = userDao.get(User.class, user.getUserId());
			sessionUser.setModifyDate(new Date());
			sessionUser.setModifier(user);
			sessionUser.setName(user.getName());
			sessionUser.setEmail(user.getEmail());
			sessionUser.setTel(user.getTel());
			sessionUser.setPhone(user.getPhone());
			sessionUser.setQuestion(user.getQuestion());
			sessionUser.setAnswer(user.getAnswer());
			sessionUser.setQqNum(user.getQqNum());
			// user = sessionUser;
			// get一下就可以加载延迟加载的属性
			if(sessionUser.getDept()!=null)sessionUser.getDept().getName();
			if(sessionUser.getJob()!=null)sessionUser.getJob().getName();
			session.setAttribute(OaContants.USER_SESSION, sessionUser);
		} catch (Exception e) {
			throw new OaException("修改用户失败了", e);
		}
		
	}
    
	@Override
	public String getAllDeptsAndJobsAjax() {
		try {
			/** 1.定义一个json对象封装最终查询出来的部门信息和职位信息 */
			JSONObject jsonObject = new JSONObject();
			/** 查询部门 ： id name 
			 * deptsList = [ {id=1，name="开发部"} , {id=2, name="销售部"} ]
			 * */
			List<Map<String , Object>> deptsList = deptDao.selectDepts();
			
			/** 查询部门 ： id name 
			 * jobLists = [ {id=1，name="java"} , {id=2, name="咨询师"} ]
			 * */
			List<Map<String , Object>> jobLists = jobDao.selectJobs();
			
			/** 把list数据转换成json数据  */
			jsonObject.put("depts", JSONArray.fromObject(deptsList).toString());
			jsonObject.put("jobs", JSONArray.fromObject(jobLists).toString());
			
			return jsonObject.toString();
		} catch (Exception e) {
			throw new OaException("查 询部门与职位信息异常了", e);
		}
	}
	
	@Override
	public List<User> getUsersByPager(User user, PageModel pageModel) {
		try {
			List<User> users = userDao.selectUsersByPager(user,pageModel);
			/** 取每个用户的延迟加载属性 */
			for(User u : users){
				if(u.getDept()!=null)u.getDept().getName();
				if(u.getJob()!=null)u.getJob().getName();
				if(u.getChecker()!=null)u.getChecker().getName();
			}
			return users;
		} catch (Exception e) {
			throw new OaException("查询用户信息异常了", e);
		}
	}
	
	@Override
	public void deleteUserByUserIds(String ids) {
		try {
			userDao.deleteBulkUsers(ids.split(","));
		} catch (Exception e) {
			throw new OaException("删除用户信息异常了", e);
		}
	}
	
	@Override
	public String isUserValidAjax(String userId) {
		try {
			User user = userDao.get(User.class, userId);
			return user==null?"success":"error";
		} catch (Exception e) {
			throw new OaException("校验用户登录名是否注册异常了", e);
		}
	}
	
	@Override
	public void addUser(User user) {
		try {
		    user.setCreateDate(new Date());
		    user.setCreater(UserHolder.getCurrentUser());
		    userDao.save(user);
		} catch (Exception e) {
			throw new OaException("添加用户信息异常了", e);
		}
		
	}
	
	@Override
	public void updateUser(User user) {
		try {
			/** 1.持久化修改   */
			User sessionUser = userDao.get(User.class, user.getUserId());
			sessionUser.setModifyDate(new Date());
			sessionUser.setModifier(UserHolder.getCurrentUser());
			sessionUser.setPassWord(user.getPassWord());
			sessionUser.setName(user.getName());
			sessionUser.setDept(user.getDept());
			sessionUser.setJob(user.getJob());
			sessionUser.setEmail(user.getEmail());
			sessionUser.setSex(user.getSex());
			sessionUser.setTel(user.getTel());
			sessionUser.setPhone(user.getPhone());
			sessionUser.setQuestion(user.getQuestion());
			sessionUser.setAnswer(user.getAnswer());
			sessionUser.setQqNum(user.getQqNum());
		} catch (Exception e) {
			throw new OaException("修改用户失败了", e);
		}
	}
	
	@Override
	public void activeUser(User user) {
		try {
			User sessionUser = userDao.get(User.class, user.getUserId());
			sessionUser.setCheckDate(new Date());
			sessionUser.setChecker(UserHolder.getCurrentUser());
			sessionUser.setStatus(user.getStatus());
		} catch (Exception e) {
			throw new OaException("激活用户失败了", e);
		}
		
	}

	@Override
	public String loadAllModuleTrees() {
		try {
			/** 查询所有的模块信息   */
			List<Module> modules = moduleDao.find(Module.class);
			/** 拼装成dtree需要的树节点  */
			/** [{id:0001,pid:0,name:用户管理} , ...]*/
			JSONArray jsonArray = new JSONArray();
			for(Module m : modules){
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("id", m.getCode());
				jsonObject.put("name", m.getName());
				// 长度为4的编号的父节点是0
				// 其余节点的父节点是从开始位置一直截取到总长度减去步长的位置。 00010001的父节点是0001
				String pid = m.getCode().length()==OaContants.CODE_LEN?"0":m.getCode().substring(0, m.getCode().length()-OaContants.CODE_LEN);
				jsonObject.put("pid", pid);
				jsonArray.add(jsonObject);
			}
			return jsonArray.toString();
		} catch (Exception e) {
			throw new OaException("加载模块树异常", e);
		}
	}
	
	@Override
	public List<Module> getModulesByParent(String parentCode,PageModel pageModel) {
		try {
			List<Module> sonModules = moduleDao.selectModuleByParent(parentCode,pageModel);
			for(Module m : sonModules){
				if(m.getCreater()!=null)m.getCreater().getName();
				if(m.getModifier()!=null)m.getModifier().getName();
			}
			return sonModules;
		} catch (Exception e) {
			throw new OaException("查询子模块异常", e);
		}
	}
	
	@Override
	public void deleteModules(String ids) {
		try {
			/** 
			 *  ids = [0001,0002]
			 * SELECT * FROM oa_id_module WHERE CODE LIKE '0001%' OR CODE LIKE '0002%';
			 *  0001% 0002%
			 * */
			moduleDao.deleteModules(ids.split(","));
		} catch (Exception e) {
			throw new OaException("批量删除菜单异常", e);
		}
		
	}
	
	@Override
	public void addModule(String parentCode, Module module) {
		try {
			
			/** 维护编号:通用工具类(给你一个父节点,给你一张表,给你那个字段,
			 *  找出该字段该父节点下的下一个儿子节点的编号 ) */
			module.setCode(generatorDao.getNextSonCode(parentCode, Module.class, "code", OaContants.CODE_LEN));
			module.setCreateDate(new Date());
			module.setCreater(UserHolder.getCurrentUser());
			moduleDao.save(module);
		} catch (Exception e) {
			throw new OaException("添加子菜单异常", e);
		}
		
	}

	@Override
	public Module getModuleByCode(String code) {
		try {
			return moduleDao.get(Module.class, code);
		} catch (Exception e) {
			throw new OaException("查询模块异常", e);
		}
	}
	
	@Override
	public void updateModule(Module module) {
		try {
			Module sessionModule = moduleDao.get(Module.class, module.getCode());
			sessionModule.setModifier(UserHolder.getCurrentUser());
			sessionModule.setModifyDate(new Date());
			sessionModule.setName(module.getName());
			sessionModule.setRemark(module.getRemark());
			sessionModule.setUrl(module.getUrl());
		} catch (Exception e) {
			throw new OaException("修改模块异常", e);
		}
		
	}
	
	@Override
	public List<Role> getRoleByPager(PageModel pageModel) {
		try {
			List<Role> roles = roleDao.selectRoleByPager(pageModel);
			for(Role r : roles){
				if(r.getModifier()!=null)r.getModifier().getName();
				if(r.getCreater()!=null)r.getCreater().getName();
			}
			return roles;
		} catch (Exception e) {
			throw new OaException("查询角色异常", e);
		}
	}
	@Override
	public void addRole(Role role) {
		try {
			role.setCreateDate(new Date());
			role.setCreater(UserHolder.getCurrentUser());
			roleDao.save(role);
		} catch (Exception e) {
			throw new OaException("添加角色异常", e);
		}
		
	}
	
	@Override
	public void deleteRole(String ids) {
		try {
			String[] id_s = ids.split(",");
			/** 1.先查再删 */
			/*
			for(String id : id_s){
				Role role = roleDao.get(Role.class, id);
				roleDao.delete(role);
			}*/
			
			/** 2.脱管态删除  */
			/*for(String id : id_s){
				Role role = new Role();
				role.setId(Long.valueOf(id));
				roleDao.delete(role);
			}*/
			
			/** 3.批量删除 */
			roleDao.deleteRolesByIds(id_s);
			
		} catch (Exception e) {
			throw new OaException("批量删除角色异常", e);
		}
	}
	
	@Override
	public Role getRoleById(Long id) {
		try {
			return roleDao.get(Role.class, id);
		} catch (Exception e) {
			throw new OaException("根据id查询角色异常", e);
		}
	}
	
	@Override
	public void updateRole(Role role) {
		try {
			Role r = roleDao.get(Role.class, role.getId());
			r.setName(role.getName());
			r.setRemark(role.getRemark());
			r.setModifier(UserHolder.getCurrentUser());
			r.setModifyDate(new Date());
		} catch (Exception e) {
			throw new OaException("根据id修改角色异常", e);
		}
		
	}

	@Override
	public List<User> selectRoleUser(Role role, PageModel pageModel) {
		try {
			List<User> users = userDao.selectUserByRole(role,pageModel);
			for(User u : users){
				if(u.getDept()!=null)u.getDept().getName();
				if(u.getJob()!=null)u.getJob().getName();
				if(u.getChecker()!=null)u.getChecker().getName();
			}
			return users;
		} catch (Exception e) {
			throw new OaException("查询属于角色下的用户信息异常", e);
		}
		
	}

	@Override
	public List<User> selectNotRoleUser(Role role, PageModel pageModel) {
		try {
			List<User> users = userDao.selectUserByNotRole(role,pageModel);
			for(User u : users){
				if(u.getDept()!=null)u.getDept().getName();
				if(u.getJob()!=null)u.getJob().getName();
				if(u.getChecker()!=null)u.getChecker().getName();
			}
			return users;
		} catch (Exception e) {
			throw new OaException("查询不属于角色下的用户信息异常", e);
		}
	}
	
	@Override
	public void bindUser(Role role, String ids) {
		try {
			/** 给角色绑定一批用户 */
			/** 1.先查询出该角色 */
			Role session = roleDao.get(Role.class, role.getId());
			/** 2.给角色的users添加需要绑定的用户 */
			for(String userId : ids.split(",")){
				User user = userDao.get(User.class, userId);
				session.getUsers().add(user);
			}
			
		} catch (Exception e) {
			throw new OaException("绑定角色下的用户异常", e);
		}
		
	}
	@Override
	public void unBindUser(Role role, String ids) {
		try {
			/** 给角色绑定一批用户 */
			/** 1.先查询出该角色 */
			Role session = roleDao.get(Role.class, role.getId());
			/** 2.给角色的users添加需要绑定的用户 */
			for(String userId : ids.split(",")){
				User user = userDao.get(User.class, userId);
				session.getUsers().remove(user);
				// User user = new user("ligang",32)
				// User user1 = new user("ligang",32)
			}
			
		} catch (Exception e) {
			throw new OaException("绑定角色下的用户异常", e);
		}
		
	}
	
	@Override
	public List<String> getRoleModuleOperasCodes(Role role, String parentCode) {
		try {
			List<String> roleModuleOperasCodes = popedomDao.selectRoleOpreasCodes(role,parentCode);
			return roleModuleOperasCodes;
		} catch (Exception e) {
			throw new OaException("查询当前角色在当前模块下拥有的操作权限编号异常", e);
		}
	}
	
	@Override
	public void bindPopedom(String codes, Role role, String parentCode) {
		try {
		    /** 1.先清空此角色在此模块下的所有操作权限 */
			popedomDao.clearRoleModuleOperas(role,parentCode);
			/** 2.更新新的角色模块权限 */
			if(!StringUtils.isEmpty(codes)){
				Module parent = getModuleByCode(parentCode);
				/** 添加一些更新的权限 */
				for(String code : codes.split(",")){
					/** 创建一个权限对象 */
					Popedom popedom = new Popedom();
					popedom.setRole(role);
					popedom.setModule(parent);
					popedom.setOpera(getModuleByCode(code));
					popedom.setCreateDate(new Date());
					popedom.setCreater(UserHolder.getCurrentUser());
					popedomDao.save(popedom);
				}
			}
		} catch (Exception e) {
			throw new OaException("给角色绑定某个模块的操作权限异常", e);
		}
		
	}
	
	@Override
	public List<UserModule> getUserPopedomModules() {
		try {
			/**查询当前用户的权限模块 ：先查用户所有的角色,再查这些角色拥有的所有权限模块  */
		    // 最终形式是一个模块编号 
			// [00010001,00010002,00010003 ,00020001,00020002,00020003 ]
			List<String> popedomModuleCodes = popedomDao.getUserPopedomModuleCodes();
			if(popedomModuleCodes!=null && popedomModuleCodes.size()>0){
				
				/** 定义一个Map集合用于保存用户的权限模块 
				 *  Map<Module,List<Module>> 
				 *  {系统管理=[用户管理,角色管理] , 假期模块=[查询信息,用户请假]}
				 *  */
			    Map<Module,List<Module>> userModulesMap = new LinkedHashMap<>();
			    Module fistModule = null ;
			    List<Module> secondModules = null ;
				for(String moduleCode : popedomModuleCodes){
					/** 截取当前模块的一级模块编号 */
					String fistCode = moduleCode.substring(0, OaContants.CODE_LEN);
					/** 查询出一级模块对象 */
					fistModule = getModuleByCode(fistCode);
					fistModule.setName(fistModule.getName().replaceAll("-", ""));
					/**如果map集合中没有包含当前一级模块的key,说明是第一次添加一级模块 */
					if(!userModulesMap.containsKey(fistModule)){
						secondModules = new ArrayList<Module>();
						userModulesMap.put(fistModule, secondModules);
					}
					Module secondModule = getModuleByCode(moduleCode);
					secondModule.setName(secondModule.getName().replaceAll("-", ""));
					secondModules.add(secondModule);
				}
				
				/** 其实此时可以直接把userModulesMap扔到界面用c标签展示出菜单即可 
				 *  我们采用对象dto封装页面数据回去 
				 *  userModulesMap = {系统管理=[用户管理,角色管理] , 假期模块=[查询信息,用户请假]}
				 * 	List<UserModule>
				 */
				
				
				List<UserModule> userModules = new ArrayList<>();
				/** 
				 *  map集合有几种遍历方式? 
				 *  10成  - 5成  - 0成
				 */
				for(Entry<Module, List<Module>> entry : userModulesMap.entrySet()){
					Module key = entry.getKey();
					List<Module> value = entry.getValue();
					UserModule userModule = new UserModule();
					userModule.setFirstModule(key);
					userModule.setSecondModules(value);
					userModules.add(userModule);
				}
				return userModules;
				
			}
			return null;
			
		} catch (Exception e) {
			throw new OaException("查询当前用户的权限模块", e);
		}
	}
	
	// session 死亡了

}
